let dayflag=true;
let weekflag=true;
let monthflag=true;
(function () {
//雷达图
var circleData = [];
 //表格初始化时间
 GetAnalysisWindowFiterTimes('tableTime', 'd', false); 
 $('#tableTime').daterangepicker(null, function (start, end, label) {
    times = $("#tableTime").val();
    getTableData(null,times);
});
$('#tableTimeControl a').click(function () {
    $(this).addClass("active").siblings().removeClass("active");
    let timeType= $(this).attr("data-type");
    GetAnalysisWindowFiterTimes('tableTime',timeType, false); 
    times = $("#tableTime").val();
    getTableData(null,times);
});
 //chart1时间初始化
 GetAnalysisWindowFiterTimes('chart1Time', 'd', false);
 $('#chart1Time').daterangepicker(null, function (start, end, label) {
    getChart1();
});
$('#Chart1TimeControl a').click(function () {
    $(this).addClass("active").siblings().removeClass("active");
    let timeType= $(this).attr("data-type");
    GetAnalysisWindowFiterTimes('chart1Time',timeType, false); 
    getChart1();
});
 //chart2时间初始化
 GetAnalysisWindowFiterTimes('chart2Time', 'd', false);
 $('#chart2Time').daterangepicker(null, function (start, end, label) {
    getChart2();
});
$('#Chart2TimeControl a').click(function () {
    $(this).addClass("active").siblings().removeClass("active");
    let timeType= $(this).attr("data-type");
    GetAnalysisWindowFiterTimes('chart2Time',timeType, false); 
    getChart2();
});
//chart3时间初始化
GetAnalysisWindowFiterTimes('chart3Time', 'd', false);
$('#chart3Time').daterangepicker(null, function (start, end, label) {
   getChart3();
});
$('#Chart3TimeControl a').click(function () {
   $(this).addClass("active").siblings().removeClass("active");
   let timeType= $(this).attr("data-type");
   GetAnalysisWindowFiterTimes('chart3Time',timeType, false); 
   getChart3();
});
//chart4时间初始化
GetAnalysisWindowFiterTimes('chart4Time', 'd', false);
$('#chart4Time').daterangepicker(null, function (start, end, label) {
   getChart4();
});
$('#Chart4TimeControl a').click(function () {
   $(this).addClass("active").siblings().removeClass("active");
   let timeType= $(this).attr("data-type");
   GetAnalysisWindowFiterTimes('chart4Time',timeType, false); 
   getChart4();
});
//chart5时间初始化
GetAnalysisWindowFiterTimes('chart5Time', 'd', false);
$('#chart5Time').daterangepicker(null, function (start, end, label) {
   getChart5();
});
$('#Chart5TimeControl a').click(function () {
   $(this).addClass("active").siblings().removeClass("active");
   let timeType= $(this).attr("data-type");
   GetAnalysisWindowFiterTimes('chart5Time',timeType, false); 
   getChart5();
});

    //获取站点
$.get("http://192.168.9.59:18902/stationEquipment/findAllStations", function (res) {
    if (res.data && res.data.length>0) {
        let data=res.data;
        for(let a=0;a<data.length;a++){
            $("#siteList").append("<option value='"+data[a].stationCode+"'>"+data[a].stationName+"</option>");
        }
        $('#siteList option:eq(1)').attr('selected','selected');
        //用站点查询传感器
        let siteVal = $("#siteList option:selected").val();
        getSensor(siteVal)
    } else {
        $("#siteList").html("<label>暂无站点!</label>");
    }
});

})();
//日期选择函数
function GetAnalysisWindowFiterTimes(valuetoid, type, event) {
    var ntime = new Date();
    if (type == 'd') {
        var dstart = ntime.format("MM/dd/yyyy");
        var dend = ntime.format("MM/dd/yyyy");
        $(".timeControl #" + valuetoid).val(dstart + " - " + dend);
    } else if (type == 'w') {
        var wstart = new Date(ntime.getTime() + (24 * 60 * 60 * -6 * 1000)).format("MM/dd/yyyy");
        var wend = ntime.format("MM/dd/yyyy");
        $(".timeControl #" + valuetoid).val(wstart + ' - ' + wend);
    } else if (type == 'm') {
        var mstart = new Date(ntime.getTime() + (24 * 60 * 60 * -30 * 1000)).format("MM/dd/yyyy");
        var mend = ntime.format("MM/dd/yyyy");
        $(".timeControl #" + valuetoid).val(mstart + ' - ' + mend);
    }
    eval(event);
}
 //用站点查询传感器
function getSensor(val){
    //0 CNSS;1降雨量;2深部位移;3地下水位
    // $.post("http://192.168.9.59:18902/stationEquipment/findByValues",{stationCode:"42032210400901000001",equipmentType:204,jscj:""}, function (res) {
    $.post("http://192.168.9.59:18902/stationEquipment/findByValues",{stationCode:val,equipmentType:204,jscj:""}, function (res) {
        $("#Chart1Select").empty();
        $("#Chart2Select").empty();
        $("#Chart3Select").empty();
        $("#Chart4Select").empty();
        $("#Chart5Select").empty();
        $("#TableSelect").empty();
        if (res.data && res.data.length>0) {
            let data=res.data;
            for(let a=0;a<data.length;a++){
                $("#Chart1Select").append("<option value='"+data[a].jscj+"' equipmentType='"+data[a].equipmentType+"' stationCode='"+data[a].stationCode+"' stationName='"+data[a].stationName+"'>"+data[a].equipmentName+"</option>");
                $("#Chart2Select").append("<option value='"+data[a].jscj+"' equipmentType='"+data[a].equipmentType+"' stationCode='"+data[a].stationCode+"' stationName='"+data[a].stationName+"'>"+data[a].equipmentName+"</option>");
                $("#Chart3Select").append("<option value='"+data[a].jscj+"' equipmentType='"+data[a].equipmentType+"' stationCode='"+data[a].stationCode+"' stationName='"+data[a].stationName+"'>"+data[a].equipmentName+"</option>");
                $("#Chart4Select").append("<option value='"+data[a].jscj+"' equipmentType='"+data[a].equipmentType+"' stationCode='"+data[a].stationCode+"' stationName='"+data[a].stationName+"'>"+data[a].equipmentName+"</option>");
                $("#Chart5Select").append("<option value='"+data[a].jscj+"' equipmentType='"+data[a].equipmentType+"' stationCode='"+data[a].stationCode+"' stationName='"+data[a].stationName+"'>"+data[a].equipmentName+"</option>");
                $("#TableSelect").append("<option value='"+data[a].jscj+"' equipmentType='"+data[a].equipmentType+"' stationCode='"+data[a].stationCode+"' stationName='"+data[a].stationName+"'>"+data[a].equipmentName+"</option>");
               
            }
            getAllData();
        } else {
            $("#Chart1Select").html("<label>暂无站点!</label>");
            $("#Chart2Select").html("<label>暂无站点!</label>");
            $("#Chart3Select").html("<label>暂无站点!</label>");
            $("#Chart4Select").html("<label>暂无站点!</label>");
            $("#Chart5Select").html("<label>暂无站点!</label>");
            $("#TableSelect").html("<label>暂无站点!</label>");
        }
       
    });
}

function siteChange(){
        //用站点查询传感器
        let siteVal = $("#siteList option:selected").val();
        getSensor(siteVal)
}
//查询所有的数据
function getAllData(){
    getChart1();
    getChart2();
    getChart3();
    getChart4();
    getChart5();
    getTableData();
}
//获取图表1的数据
function getChart1(){
    let sensorVal=$("#Chart1Select option:selected").val();
    let timeVal=$("#chart1Time").val();
    var startTimeSplit = timeVal.split('-')[0].replace(" ", "").split('/'),
        endTimeSplit = timeVal.split('-')[1].replace(" ", "").split('/');
    var startTime = startTimeSplit[2] + "-" + startTimeSplit[0] + "-" + startTimeSplit[1]+" 00:00:00";
    var endTime = endTimeSplit[2] + "-" + endTimeSplit[0] + "-" + endTimeSplit[1]+" 23:59:59";
    // let startTime;
    // let endTime= new Date().format("yyyy-MM-dd")+" 23:59:59";
    // let flagName;
    // if(dayflag){
    //     flagName="dayflag";
    //     startTime= new Date().format("yyyy-MM-dd")+" 00:00:00";
    // }else if(weekflag){
    //     flagName="weekflag";
    //     startTime= new Date(new Date()-7*24*3600*1000).format("yyyy-MM-dd")+" 00:00:00";
    // }else if(monthflag){
    //     flagName="monthflag";
    //     startTime= new Date(new Date()-30*24*3600*1000).format("yyyy-MM-dd")+" 00:00:00";
    // }
    var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=" + sensorVal;
    //请求
    let dataList=[];
    var chartData = new Array();
    circleData = [];
    var datatimes = new Array();
    datatimes.push(new Date().format("yyyy-MM-dd hh:mm:ss"));
    var e = new Object(); e.name = "E"; e.datatype = "0"; e.data = new Array(); chartData.push(e);
    var n = new Object(); n.name = "N"; n.datatype = "0"; n.data = new Array(); chartData.push(n);
    var u = new Object(); u.name = "U"; u.datatype = "0"; u.data = new Array(); chartData.push(u);

    $.get(postUrl, function (res) {
        if (res.msg == 'success' && res.data && res.data.length>0) {
            let dataList=[];
            let data = res.data;
            let column = res.column;
            for(let a=0;a<data.length;a++){
                    let li={}
                    for(let b=0;b<column.length;b++){
                        let key =column[b];
                        li[column[b]]=data[a][b];
                    }
                    dataList.push(li)
            }
            dataList.forEach((li,index)=>{
                var ndate;
                if(index == 0){
                    ndate = new Date(li.time);
                }
                if(li.JCSJ204A030){//{field:'JCSJ204A030',  title: 'X'}
                    chartData[0].data.push([new Date(li.time).getTime(), li.JCSJ204A030]);
                }else{
                    chartData[0].data.push([new Date(li.time).getTime(), 0]);
                }
                if(li.JCSJ204A031){//{field:'JCSJ204A031', title: 'Y'}
                    chartData[1].data.push([new Date(li.time).getTime(), li.JCSJ204A031]);
                }else{
                    chartData[1].data.push([new Date(li.time).getTime(), 0]);
                }
                if(li.JCSJ204A032){//{field:'JCSJ204A032', title: 'Z'}
                    chartData[2].data.push([new Date(li.time).getTime(),li.JCSJ204A032]);
                }else{
                    chartData[2].data.push([new Date(li.time).getTime(), 0]);
                }
                if(li.JCSJ204A030 && li.JCSJ204A030){
                    circleData.push(
                        [
                            getLength(li.JCSJ204A030, li.JCSJ204A031),
                            getAngle(li.JCSJ204A030, li.JCSJ204A031),
                            li.time,
                            li.JCSJ204A030.toFixed(2) * 1,
                            li.JCSJ204A031.toFixed(2) * 1
                        ]
                    );
                }else{ 
                    circleData.push(
                        [
                            getLength(li.JCSJ204A030||0, li.JCSJ204A031||0),
                            getAngle(li.JCSJ204A030||0, li.JCSJ204A031||0),
                            // ndate.format("yyyy-MM-dd hh:mm:ss"),
                            li.time,
                            li.JCSJ204A030.toFixed(2) * 1||0,
                            li.JCSJ204A031.toFixed(2) * 1||0
                        ]
                    );
                }
            })
            InsRealChart(datatimes, chartData);
            LoadStartRealGnssCircleChart();
        }else{
            // if(flagName =="dayflag"){
            //     dayflag=false;
            // }
            // if(flagName =="weekflag"){
            //     weekflag=false;
            // }
            // if(flagName =="monthflag"){
            //     monthflag=false;
            // }
            // getChart1()
        }
    })

}
 //获取x，
function getLength(mx, my) {
    return Math.floor(Math.sqrt(mx * mx + my * my) * 100) / 100;
}
//获取Y
function getAngle(mx, my) {//获得人物中心和鼠标坐标连线，与y轴正半轴之间的夹角
    var x = Math.abs(mx);
    var y = Math.abs(my);
    var z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
    var cos = y / z;
    var radina = Math.asin(cos);//用反三角函数求弧度
    var angle = Math.floor(180 / (Math.PI / radina));//将弧度转换成角度
    if (mx > 0 && my > 0) {//鼠标在第二象限
        angle = 360 - angle;
    };
    if (mx < 0 && my > 0) {//鼠标在第二象限
        angle = 180 + angle;
    };
    if (mx < 0 && my < 0) {//鼠标在第三象限
        angle = 180 - angle;
    };
    if (mx < 0 && my == 0) {//鼠标在x轴负方向上
        angle = 180;
    };
    if (mx == 0 && my > 0) {//鼠标在Y轴正方向上
        angle = 270;
    };
    return angle;
}
function InsRealChart(datatimes, chartData) {
    let option={
        chart: {
            type: 'line',
            animation: Highcharts.svg,
            marginRight: 110,
        },
        colors: ['#7FBF7F', '#7F7FFF', '#FF6F10', '#8756D8', '#FF7F7F'],
        title: { text: '', enabled: false },
        xAxis: { type: 'datetime' },
        yAxis: { title: { text: "GNSS" }, plotLines: [{ value: 0, width: 1, color: '#999' }] },
        tooltip: { formatter: function () { var date = new Date(this.x); return "时间:[" + date.format("yyyy-MM-dd hh:mm:ss") + "]<br>数据:[" + this.y + " mm]"; } },
        legend: { align: 'right', verticalAlign: 'center', x: 0, y: 0, layout: 'vertical', enabled: true },
        credits: { enabled: false },
        exporting: { enabled: false },
        plotOptions: { spline: { marker: { enabled: false } } },
        series: chartData,
        lang: { noData: "数据接收中..." },
        noData: { position: { align: 'center', verticalAlign: 'center' }, attr: { 'stroke-width': 1, stroke: '#EFEFEF' }, style: { fontSize: '14px', color: '#999', fontWeight: "normal" } }
    }
    $("#linechart").highcharts(option);
}

var cicleOption = {
    title: { text: '平面E/N坐标展示图(mm)', textStyle: { fontSize: 14, fontWeight: "normal", color: "#666666" } },
    polar: {},
    tooltip: {
        formatter: function (params) {
            return "时间:" + params.value[2] + "<br>E:" + params.value[3] + "mm<br>N:" + params.value[4] + "mm"
        }
    },
    angleAxis: {
        type: 'value',
        startAngle: 0,
        min: 0, max: 360,
        interval: 30,
        axisLabel: {
            formatter: function (value) {
                if (value == 0) {
                    return "E";
                } else if (value == 90) {
                    return "S";
                } else if (value == 180) {
                    return "W";
                } else if (value == 270) {
                    return "N";
                } else {
                    return value + "°";
                };
            }
        }
    },
    radiusAxis: { axisAngle: 0 },
    series: [{
        coordinateSystem: 'polar',
        angleAxisIndex: 0,
        radiusAxisIndex: 0,
        name: 'scatter',
        type: 'line',
        symbolSize: 6,
        data: []
    }]
};
function LoadStartRealGnssCircleChart() {
    var circlechart = echarts.init(document.getElementById('circlechart'));
    cicleOption.series[0].data = circleData;
    circlechart.setOption(
        cicleOption
    );
}
//获取图表2的数据
function getChart2(){
    let sensorVal=$("#Chart2Select option:selected").val(); 
    let timeVal=$("#chart2Time").val();
    var startTimeSplit = timeVal.split('-')[0].replace(" ", "").split('/'),
        endTimeSplit = timeVal.split('-')[1].replace(" ", "").split('/');
    var startTime = startTimeSplit[2] + "-" + startTimeSplit[0] + "-" + startTimeSplit[1]+" 00:00:00";
    var endTime = endTimeSplit[2] + "-" + endTimeSplit[0] + "-" + endTimeSplit[1]+" 23:59:59";
    // var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=01010100399";  
    var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=" + sensorVal;
    //请求
    $.get(postUrl, function (res) {
        if(res.msg=="success" && res.data){
            let data = res.data;
            let column = res.column;
            let Chart2Data=[];
            for(let a=0;a< data.length;a++){
                    let li={}
                    for(let b=0;b<column.length;b++){
                        let key =column[b];
                        li[column[b]]=data[a][b];
                    }
                    Chart2Data.push(li)
            }
            var tempData = [];
            //格式化x
            var temp_x = {};
            temp_x.name = "x";
            temp_x.dataType = "0";
            temp_x.data = [];
            Chart2Data.forEach((li)=>{
                temp_x.data.push([new Date(li.time).getTime(), li.JCSJ204A030]);
            })
            tempData.push(temp_x);

            //格式化y
            var temp_y = {};
            temp_y.name = "y";
            temp_y.dataType = "0";
            temp_y.data = [];
            Chart2Data.forEach((li)=>{
                temp_y.data.push([new Date(li.time).getTime(), li.JCSJ204A031]);
            })
            tempData.push(temp_y);

            //格式化z
            var temp_z = {};
            temp_z.name = "z";
            temp_z.dataType = "0";
            temp_z.data = [];
            Chart2Data.forEach((li)=>{
                temp_z.data.push([new Date(li.time).getTime(), li.JCSJ204A032]);
            })
            tempData.push(temp_z);

            //格式化3d
            var temp_3d = {};
            temp_3d.name = "3d";
            temp_3d.dataType = "0";
            temp_3d.data = [];
            Chart2Data.forEach((li)=>{
                temp_3d.data.push([new Date(li.time).getTime(), li.JCSJ204A033]);
            })
            tempData.push(temp_3d);

            //格式化2d
            var temp_2d = {};
            temp_2d.name = "2d";
            temp_2d.dataType = "0";
            temp_2d.data = [];
            Chart2Data.forEach((li)=>{
                temp_2d.data.push([new Date(li.time).getTime(), li.JCSJ204A034]);
            })
            tempData.push(temp_2d);

            var chartData = tempData;
            if (chartData != "") {
                var accumulativeChartType = [0];
                var accumulativeDataUnits = ["GNSS：mm", "mm"];
                var timeFormatUnit = "yyyy-MM-dd hh:mm:ss";
                var showChartDatas = [];

                var nDatas = chartData;
                for (var j = 0; j < chartData.length; j++) {
                    nDatas[j].name = nDatas[j].name;
                    showChartDatas.push(nDatas[j]);
                }
                let option={
                    chart: { type: 'spline', backgroundColor: { linearGradient: { x1: 0, y1: 0, x2: 1, y2: 1 }, stops: [[0, '#EAEAEA'], [1, '#EAEAEA']] }, style: { fontFamily: "'Unica One', sans-serif" }, plotBorderColor: '#606063', zoomType: 'x', spacingRight: 20, height: 380 },
                    colors: ['#E5561F', '#7FBF7F', '#7F7FFF', '#FF6F10', '#8756D8', '#310F39', '#FF7F7F'],
                    title: { text: '' },
                    credits: { enabled: false },
                    exporting: { enabled: false },
                    subtitle: { text: '' },
                    xAxis: { type: 'datetime', tickInterval:100,dateTimeLabelFormats: { month: '%y年%m月', day: '%m月%e日', week: '%m月%e日', hour: '%H:%M' }, lineColor: 'red', tickColor: '#222', labels: { style: { color: '#222' } }, tickWidth: 2, tickmarkPlacement: 'on' },
                    labels: { style: { color: '#222' } },
                    yAxis: { title: { text: accumulativeDataUnits[0], style: { color: '#222' } }, plotLines: [{ value: 0, width: 1, color: '#808080' }], tickColor: '#222', labels: { style: { color: '#222' } }, tickWidth: 2, lineColor: 'red' },
                    plotOptions: { spline: { lineWidth: 1.5, states: { hover: { lineWidth: 2.5 } }, marker: { enabled: false } } },
                    tooltip: {
                        formatter: function () {
                            return "测点:[<b>" + this.series.name + "</b>]<br>时间:[" + (new Date(this.x)).format(timeFormatUnit) + "]<br>数据:<ul>" + this.y + "mm</ul>";
                        }
                    },
                    series: showChartDatas
                }
                $('#chart2Content').highcharts(option);
            }


        }else{
            $("#chart2Content").html("<label>未能成功加载GNSS数据!</label>");
        }
    })
}
//获取图表3的数据
function getChart3(){
    let sensorVal=$("#Chart3Select option:selected").val(); 
    let timeVal=$("#chart3Time").val();
    var startTimeSplit = timeVal.split('-')[0].replace(" ", "").split('/'),
        endTimeSplit = timeVal.split('-')[1].replace(" ", "").split('/');
    var startTime = startTimeSplit[2] + "-" + startTimeSplit[0] + "-" + startTimeSplit[1]+" 00:00:00";
    var endTime = endTimeSplit[2] + "-" + endTimeSplit[0] + "-" + endTimeSplit[1]+" 23:59:59";
    // var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=01010100399";  
    var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=" + sensorVal;
    //请求
    $.get(postUrl, function (res) {
        if(res.msg=="success" && res.data){
            let data = res.data;
            let column = res.column;
            let Chart2Data=[];
            for(let a=0;a< data.length;a++){
                    let li={}
                    for(let b=0;b<column.length;b++){
                        let key =column[b];
                        li[column[b]]=data[a][b];
                    }
                    Chart2Data.push(li)
            }

            var tempData = [];
            var speed = {};
            speed.name = "speed";
            speed.dataType = "0";
            speed.data = [];
            Chart2Data.forEach((li)=>{
                if(li.speed){
                    speed.data.push([new Date(li.time).getTime(), li.speed*1]);
                }
            })
            tempData.push(speed);
            var chartData = tempData;
            if (chartData != "") {
                var accumulativeChartType = [0];
                var accumulativeDataUnits = ["GNSS速率:mm/h"];
                var timeFormatUnit = "yyyy-MM-dd hh:mm:ss";
                var showChartDatas = [];

                var nDatas = chartData;
                for (var j = 0; j < chartData.length; j++) {
                    nDatas[j].name = '位移速率'+ nDatas[j].name;
                    showChartDatas.push(nDatas[j]);
                }
                let option2={
                    chart: { type: 'spline', backgroundColor: { linearGradient: { x1: 0, y1: 0, x2: 1, y2: 1 }, stops: [[0, '#EAEAEA'], [1, '#EAEAEA']] }, style: { fontFamily: "'Unica One', sans-serif" }, plotBorderColor: '#606063', zoomType: 'x', spacingRight: 20, height: 380 },
                    colors: [ '#FF6F10', '#8756D8', '#310F39', '#FF7F7F'],
                    title: { text: '' },
                    credits: { enabled: false },
                    exporting: { enabled: false },
                    subtitle: { text: '' },
                    xAxis: { type: 'datetime', dateTimeLabelFormats: { month: '%y年%m月', day: '%m月%e日', week: '%m月%e日', hour: '%H:%M' }, lineColor: 'red', tickColor: '#222', labels: { style: { color: '#222' } }, tickWidth: 2, tickmarkPlacement: 'on' },
                    labels: { style: { color: '#222' } },
                    yAxis: { title: { text: accumulativeDataUnits[0], style: { color: '#222' } }, plotLines: [{ value: 0, width: 1, color: '#808080' }], tickColor: '#222', labels: { style: { color: '#222' } }, tickWidth: 2, lineColor: 'red' },
                    plotOptions: { spline: { lineWidth: 1.5, states: { hover: { lineWidth: 2.5 } }, marker: { enabled: false } } },
                    tooltip: {
                        formatter: function () {
                            return "测点:[<b>" + this.series.name + "</b>]<br>时间:[" + (new Date(this.x)).format(timeFormatUnit) + "]<br>数据:<ul>" + this.y + "mm</ul>";
                        }
                    },
                    series: showChartDatas
                }
                $('#chart3Content').highcharts(option2);
            }

        }else{
            $("#chart3Content").html("<label>未能成功加载GNSS数据!</label>");
        }
    })
}
//获取图表4的数据
function getChart4(){
    let sensorVal=$("#Chart4Select option:selected").val(); 
    let timeVal=$("#chart4Time").val();
    var startTimeSplit = timeVal.split('-')[0].replace(" ", "").split('/'),
        endTimeSplit = timeVal.split('-')[1].replace(" ", "").split('/');
    var startTime = startTimeSplit[2] + "-" + startTimeSplit[0] + "-" + startTimeSplit[1]+" 00:00:00";
    var endTime = endTimeSplit[2] + "-" + endTimeSplit[0] + "-" + endTimeSplit[1]+" 23:59:59";
    // var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=01010100399";
    var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=" + sensorVal;
    //请求
    $.get(postUrl, function (res) {
        if(res.msg=="success" && res.data){
            let data = res.data;
            let column = res.column;
            let Chart2Data=[];
            for(let a=0;a< data.length;a++){
                    let li={}
                    for(let b=0;b<column.length;b++){
                        let key =column[b];
                        li[column[b]]=data[a][b];
                    }
                    Chart2Data.push(li)
            }

            var tempData = [];
            var speed = {};
            speed.name = "angle";
            speed.dataType = "0";
            speed.data = [];
            Chart2Data.forEach((li)=>{
                if(li.speed){
                    speed.data.push([new Date(li.time).getTime(), li.angle*1]);
                }
            })
            tempData.push(speed);
            var chartData = tempData;
            if (chartData != "") {
                var accumulativeChartType = [0];
                var accumulativeDataUnits = ["T唯一时间纲量"];
                var timeFormatUnit = "yyyy-MM-dd hh:mm:ss";
                var showChartDatas = [];

                var nDatas = chartData;
                for (var j = 0; j < chartData.length; j++) {
                    nDatas[j].name = '切线角'+ nDatas[j].name;
                    showChartDatas.push(nDatas[j]);
                }
                let option2={
                    chart: { type: 'spline', backgroundColor: { linearGradient: { x1: 0, y1: 0, x2: 1, y2: 1 }, stops: [[0, '#EAEAEA'], [1, '#EAEAEA']] }, style: { fontFamily: "'Unica One', sans-serif" }, plotBorderColor: '#606063', zoomType: 'x', spacingRight: 20, height: 380 },
                    colors: [ '#7F7FFF', '#FF6F10', '#8756D8', '#310F39', '#FF7F7F'],
                    title: { text: '' },
                    credits: { enabled: false },
                    exporting: { enabled: false },
                    subtitle: { text: '' },
                    xAxis: { type: 'datetime', dateTimeLabelFormats: { month: '%y年%m月', day: '%m月%e日', week: '%m月%e日', hour: '%H:%M' }, lineColor: 'red', tickColor: '#222', labels: { style: { color: '#222' } }, tickWidth: 2, tickmarkPlacement: 'on' },
                    labels: { style: { color: '#222' } },
                    yAxis: { title: { text: accumulativeDataUnits[0], style: { color: '#222' } }, plotLines: [{ value: 0, width: 1, color: '#808080' }], tickColor: '#222', labels: { style: { color: '#222' } }, tickWidth: 2, lineColor: 'red' },
                    plotOptions: { spline: { lineWidth: 1.5, states: { hover: { lineWidth: 2.5 } }, marker: { enabled: false } } },
                    tooltip: {
                        formatter: function () {
                            return "测点:[<b>" + this.series.name + "</b>]<br>时间:[" + (new Date(this.x)).format(timeFormatUnit) + "]<br>数据:<ul>" + this.y + "°</ul>";
                        }
                    },
                    series: showChartDatas
                }
                $('#chart4Content').highcharts(option2);
            }

        }else{
            $("#chart4Content").html("<label>未能成功加载GNSS数据!</label>");
        }
    })
}
//获取图表5的数据
function getChart5(){
    let sensorVal=$("#Chart5Select option:selected").val(); 
    let timeVal=$("#chart5Time").val();
    var startTimeSplit = timeVal.split('-')[0].replace(" ", "").split('/'),
        endTimeSplit = timeVal.split('-')[1].replace(" ", "").split('/');
    var startTime = startTimeSplit[2] + "-" + startTimeSplit[0] + "-" + startTimeSplit[1]+" 00:00:00";
    var endTime = endTimeSplit[2] + "-" + endTimeSplit[0] + "-" + endTimeSplit[1]+" 23:59:59";
    // var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=01010100399";
    var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=" + sensorVal;
    //请求
    $.get(postUrl, function (res) {
        if(res.msg=="success" && res.data){
            let data = res.data;
            let column = res.column;
            let Chart2Data=[];
            for(let a=0;a< data.length;a++){
                    let li={}
                    for(let b=0;b<column.length;b++){
                        let key =column[b];
                        li[column[b]]=data[a][b];
                    }
                    Chart2Data.push(li)
            }

            var tempData = [];
            var speed = {};
            speed.name = "acceleration";
            speed.dataType = "0";
            speed.data = [];
            Chart2Data.forEach((li)=>{
                if(li.speed){
                    speed.data.push([new Date(li.time).getTime(), li.acceleration*1]);
                }
            })
            tempData.push(speed);
            var chartData = tempData;
            if (chartData != "") {
                var accumulativeChartType = [0];
                var accumulativeDataUnits = ["加速度:mm/h²"];
                var timeFormatUnit = "yyyy-MM-dd hh:mm:ss";
                var showChartDatas = [];

                var nDatas = chartData;
                for (var j = 0; j < chartData.length; j++) {
                    nDatas[j].name = '加速度'+ nDatas[j].name;
                    showChartDatas.push(nDatas[j]);
                }
                let option2={
                    chart: { type: 'spline', backgroundColor: { linearGradient: { x1: 0, y1: 0, x2: 1, y2: 1 }, stops: [[0, '#EAEAEA'], [1, '#EAEAEA']] }, style: { fontFamily: "'Unica One', sans-serif" }, plotBorderColor: '#606063', zoomType: 'x', spacingRight: 20, height: 380 },
                    colors: [ '#7FBF7F', '#7F7FFF', '#FF6F10', '#8756D8', '#310F39', '#FF7F7F'],
                    title: { text: '' },
                    credits: { enabled: false },
                    exporting: { enabled: false },
                    subtitle: { text: '' },
                    xAxis: { type: 'datetime', dateTimeLabelFormats: { month: '%y年%m月', day: '%m月%e日', week: '%m月%e日', hour: '%H:%M' }, lineColor: 'red', tickColor: '#222', labels: { style: { color: '#222' } }, tickWidth: 2, tickmarkPlacement: 'on' },
                    labels: { style: { color: '#222' } },
                    yAxis: { title: { text: accumulativeDataUnits[0], style: { color: '#222' } }, plotLines: [{ value: 0, width: 1, color: '#808080' }], tickColor: '#222', labels: { style: { color: '#222' } }, tickWidth: 2, lineColor: 'red' },
                    plotOptions: { spline: { lineWidth: 1.5, states: { hover: { lineWidth: 2.5 } }, marker: { enabled: false } } },
                    tooltip: {
                        formatter: function () {
                            return "测点:[<b>" + this.series.name + "</b>]<br>时间:[" + (new Date(this.x)).format(timeFormatUnit) + "]<br>数据:<ul>" + this.y + "mm/h²</ul>";
                        }
                    },
                    series: showChartDatas
                }
                $('#chart5Content').highcharts(option2);
            }

        }else{
            $("#chart5Content").html("<label>未能成功加载GNSS数据!</label>");
        }
    })
}
//获取表格数据
function getTableData(sensor,time){
    let sensorVal=sensor;let timeVal=time;
    if(!sensorVal){
        sensorVal = $("#TableSelect option:selected").val(); 
    }
    if(!timeVal){
        timeVal=$("#tableTime").val();
    }
    var startTimeSplit = timeVal.split('-')[0].replace(" ", "").split('/'),
        endTimeSplit = timeVal.split('-')[1].replace(" ", "").split('/');
    var startTime = startTimeSplit[2] + "-" + startTimeSplit[0] + "-" + startTimeSplit[1]+" 00:00:00";
    var endTime = endTimeSplit[2] + "-" + endTimeSplit[0] + "-" + endTimeSplit[1]+" 23:59:59";
    
    // var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=01010100399";
    var postUrl = "http://192.168.9.59:801/apis/result/query204a1/?startTime="+ startTime +"&endTime="+ endTime +"&uniqure_code=" + sensorVal;
    //请求
    let dataList=[];
    $.get(postUrl, function (res) {
        if(res.msg=="success" && res.data){
            let data = res.data;
            let column = res.column;
            let dataList=[];
            for(let a=0;a<data.length;a++){
                    let li={}
                    for(let b=0;b<column.length;b++){
                        let key =column[b];
                        li[column[b]]=data[a][b];
                    }
                    dataList.push(li)
            }
            layui.use(['table','layer','form','layedit','laydate'], function(){
                var table = layui.table;
                var layer=layui.layer;
                var layedit = layui.layedit;
                var form=layui.form;
                var $=layui.$;
                var laydate = layui.laydate;
                table.render({
                    elem: '#idTest'
                    ,data: dataList
                    ,contentType: "application/x-www-form-urlencoded"
                    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                        layout: [ 'prev', 'page', 'next', 'skip','limit', 'count',] //自定义分页布局
                        //,curr: 5 //设定初始在第 5 页
                        ,limit:10 //一页显示多少条
                        ,limits:[5,10,15]//每页条数的选择项
                        ,groups: 2 //只显示 2 个连续页码
                        ,first: "首页" //不显示首页
                        ,last: "尾页" //不显示尾页
                        }
                        ,where:{ispage: true }
                        ,even:true
                        ,page: true  //是否启用分页
                        ,done:function(res, curr, count){ }
                        ,cols: [[
                                    ,{field:'time',  title: '监测时间',width:160}
                                    ,{field:'JCSJ204A030',  title: 'X'}
                                    ,{field:'JCSJ204A031', title: 'Y'}
                                    ,{field:'JCSJ204A032', title: 'Z'}
                                    ,{field:'JCSJ204A033', title: '合位移'}
                                    ,{field:'JCSJ204A060', title: '设备类型编号'}
                                    ,{field:'JCSJ204A070', title: '传感器'}
                                    ,{field:'speed', title: '位移速率'}
                                    ,{field:'angle', title: '切线角'}
                                    ,{field:'acceleration', title: '加速度'}
                                        
                        ]]
                    });
            })
        }else{
            $("#idTest").html("<p>暂无数据</p>")
        }
    }) 
}
